﻿//////////////////////////////////////////////////////////////////////////////
//
//  Copyright © 1998-2024 Glodon Company Limited.  All rights reserved.
//
//  Use of this software is subject to the terms of the Glodon license
//  agreement provided at the time of installation or download, or which
//  otherwise accompanies this software in either electronic or hard copy form.  
//
//////////////////////////////////////////////////////////////////////////////


#pragma once
#include "GnufBase.h"
#include "GnufImpl.h"
#include "GnufComponent.h"
#include "GnufItemEvents.h"
#include "GnufModuleManager.h"

namespace gnuf {
    class WorkspaceTab;
    namespace impl { class GNUF_IMPL_CLASS(MainTitleBar); }
    class GNUF_BASE_EXPORT MainTitleBar final
    {
        GNUF_IMPL_USE(MainTitleBar);
    public:
        /// \brief 构造函数
        /// \param key component的key
        /// \param config 配置信息的字符串
        /// \param file 配置信息是否为文件
        /// - true代表xml文件
        /// - false代表wstring的xml描述
        /// \return 
        MainTitleBar(const std::wstring & key, const std::wstring & config, bool file = true);
        ~MainTitleBar();
        static MainTitleBar * get();
        WorkspaceTabBar * addWorkspaceTabBar();
        const WorkspaceTabBar * workspaceTabBar() const;
        WorkspaceTabBar * workspaceTabBar();
        const WorkspaceTab * currentWorkspaceTab() const;
        WorkspaceTab * currentWorkspaceTab();
    };
}

namespace gnuf { namespace impl {
    class GNUF_IMPL_CLASS(MainTitleBar) final
        : public Component
        , public IItemEventHandler
    {
        GNUF_IMPL_USED_BY(MainTitleBar);
    public:
        GNUF_IMPL_CLASS(MainTitleBar)(
            MainTitleBar * pMtb,
            const std::wstring & key,
            const std::wstring & config,
            bool file);

        ~GNUF_IMPL_CLASS(MainTitleBar)();
        GNUF_IMPL_CLASS(MainTitleBar)(
            MainTitleBar* pMtb,
            const std::wstring& key,
            gcmp::OwnerPtr<gnuf::ConfigurationInfo> opConfig);

        WorkspaceTabBar * addWorkspaceTabBar();
        const WorkspaceTabBar * workspaceTabBar() const;
        WorkspaceTabBar * workspaceTabBar();
        const WorkspaceTab * currentWorkspaceTab() const;
        WorkspaceTab * currentWorkspaceTab();
    protected:
        // Inherits from Component...
        virtual void initialize(Toolbar *) override;
        virtual gcmp::OwnerPtr<QtToolbar> createQtToolBar(Toolbar*) override;
        virtual bool hasSiblings(Component::Ones *) const override;
        virtual ETransferingContentMethod decideTransferringContentMethod(
            const Item * pSender, const Item * pAcceptor, const Item * pContent) const override;
        virtual void onPostDumpFromConfigString();
        
        // Inherits from IItemEventHandler...
        virtual void onHovered(Item *, bool, void *) override;
        virtual bool onPreClicked(Item *) override;
        virtual void onCurrentIndexChanged(WorkspaceTabBar *) override;
        virtual bool onDoesApproveOfSwitching(WorkspaceTabBar *, WorkspaceTab *, WorkspaceTab *) override;
    };
} }
